#ifndef FILE_LIST_FINDER_H
#define FILE_LIST_FINDER_H

#include <stdio.h>
#include <dirent.h>
#include <iostream>


using namespace std;

class FileListFinder {
		public:
		
		vector < string > list;
				
		int find(string dirname, string mask="") {
					
			DIR *dir;
			dirent *ent; // entry
					
			if ((dir=opendir(dirname.c_str())) == NULL) { perror("Error: can't open directory"); return -1; }
			
			list.erase(list.begin(), list.begin()+list.size());
			
			while ((ent=readdir(dir)) != NULL)
				if ( mask=="" || (mask!="" && string(ent->d_name).find(mask) != std::string::npos)  )
					list.push_back(string(ent->d_name));
		
			closedir(dir);
					
			return 0;
		}
		
		void print() {
			for (uint i = 0; i<list.size();i++)
			cout << list[i] << endl;
		}
				
};


#endif
